<template>
  <div class="divBox">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <div class="container">
          <el-form size="small" inline label-width="100px">
            <el-form-item label="订单状态：">
              <el-radio-group
                v-model="tableFrom.status"
                type="button"
                @change="getList(1)"
              >
                <el-radio-button label="" @click="test()">全部</el-radio-button>
                <el-radio-button label="1">待付款</el-radio-button>
                <el-radio-button label="2">待发货</el-radio-button>
                <el-radio-button label="3">待收货</el-radio-button>
                <el-radio-button label="4">待评价</el-radio-button>
                <el-radio-button label="5">交易完成</el-radio-button>
                <el-radio-button label="6">已退款</el-radio-button>
                <el-radio-button label="7">已删除</el-radio-button>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="订单生成时间" class="width100">
              <el-date-picker
                v-model="timeVal"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy/MM/dd"
                format="yyyy/MM/dd"
                :picker-options="pickerOptions"
                @change="onchangeTime"
              ></el-date-picker>
            </el-form-item>
            <el-form-item
              label="订单号"
              class="width100"
              style="display: inline-block;"
            >
              <el-input
                v-model="tableFrom.order_sn"
                placeholder="请输入订单号"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
            </el-form-item>
            <el-form-item
              label="物流单号"
              class="width100"
              style="display: inline-block;"
            >
              <el-input
                v-model="tableFrom.delivery_id"
                placeholder="请输入物流单号"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
            </el-form-item>
            <el-form-item
              label="联系电话"
              class="width100"
              style="display: inline-block;"
            >
              <el-input
                v-model="tableFrom.user_phone"
                placeholder="请输入联系电话"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
            </el-form-item>
            <el-form-item
              label="身份证号"
              class="width100"
              style="display: inline-block;"
            >
              <el-input
                v-model="tableFrom.user_card"
                placeholder="请输入身份证号"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
            </el-form-item>
            <el-form-item
              label="生产号码"
              class="width100"
              style="display: inline-block;"
            >
              <el-input
                v-model="tableFrom.phone"
                placeholder="请输入生产号码"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
            </el-form-item>
            <el-form-item
              label="商品名称"
              class="width100"
              style="display: inline-block;"
            >
              <el-input
                v-model="tableFrom.store_name"
                placeholder="请输入商品名称"
                class="selWidth"
                size="small"
                @keyup.enter.native="getList(1)"
              >
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  size="small"
                  class="el-button-solt"
                  @click="getList(1)"
                />
              </el-input>
            </el-form-item>
            <el-form-item
              label="开卡状态"
              class="width100"
              style="display: inline-block;"
            >
              <el-select
                v-model="tableFrom.speed_status"
                clearable
                filterable
                placeholder="请选择"
                class="selWidth"
                @change="getList(1)"
              >
                <el-option
                  v-for="item in cardStatusList"
                  :key="item.type"
                  :label="item.name"
                  :value="item.type"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              label="激活状态"
              class="width100"
              style="display: inline-block;"
            >
              <el-select
                v-model="tableFrom.open_status"
                clearable
                filterable
                placeholder="请选择"
                class="selWidth"
                @change="getList(1)"
              >
                <el-option label="未激活" value="0" />
                <el-option label="已激活" value="1" />
              </el-select>
            </el-form-item>
            <el-form-item
              label="是否首充"
              class="width100"
              style="display: inline-block;"
            >
              <el-select
                v-model="tableFrom.save_status"
                clearable
                filterable
                placeholder="请选择"
                class="selWidth"
                @change="getList(1)"
              >
                <el-option label="未首充" value="0" />
                <el-option label="已首充" value="1" />
              </el-select>
              <el-button size="small" type="primary" @click="getExportFileList"
                >导出记录</el-button
              >
            </el-form-item>
          </el-form>
        </div>

        <el-tabs
          v-if="headeNum.length > 0"
          v-model="tableFrom.order_type"
          @tab-click="getList(1)"
        >
          <el-tab-pane
            v-for="(item, index) in headeNum"
            :key="index"
            :name="item.order_type.toString()"
            :label="item.title + '(' + item.count + ')'"
          />
        </el-tabs>
      </div>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%;"
        height="700px"
        size="mini"
        class="table"
        highlight-current-row
      >
        <el-table-column label="订单信息" min-width="250">
          <template slot-scope="scope">
            <div>
              订单号：
              <span v-text="scope.row.order_sn" />
              <span
                v-show="scope.row.is_del > 0"
                style="color: #ED4014;display: block;"
                >(用户已删除)</span
              >
            </div>
            <div>
              实际支付：<span>{{ scope.row.pay_price }}</span>
              <p v-if="scope.row.finalOrder">
                尾款：{{ scope.row.finalOrder.pay_price }}
              </p>
            </div>
            <div>
              支付状态：<span
                :class="{
                  redColor: scope.row.paid == 0,
                  greenColor: scope.row.paid !== 0
                }"
                >{{ scope.row.paid == 0 ? "未支付" : "已支付" }}</span
              >
            </div>
            <div>
              支付方式：
              <span v-if="scope.row.paid === 1">{{
                scope.row.pay_type | orderPayType
              }}</span>
              <span v-else>--</span>
            </div>
            <div>
              订单状态：
              <span v-if="scope.row.is_del === 0">
                <span class="redColor" v-if="scope.row.paid === 0">待付款</span>
                <span v-else>
                  <span
                    v-if="
                      scope.row.order_type === 0 || scope.row.order_type === 2
                    "
                    >{{ scope.row.status | orderStatusFilter }}</span
                  >
                  <span v-else>{{
                    scope.row.status | takeOrderStatusFilter
                  }}</span>
                </span>
              </span>
              <span class="redColor" v-else>已删除</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="商品信息" min-width="400">
          <template slot-scope="scope">
            <div>
              <span>商品名称：</span>
              <div style="display: inline-block;">
                <div
                  v-for="(val, i) in scope.row.orderProduct"
                  :key="i"
                  class="tabBox acea-row row-middle"
                >
                  <div class="demo-image__preview">
                    <el-image
                      :src="val.cart_info.product.image"
                      :preview-src-list="[val.cart_info.product.image]"
                    />
                  </div>
                  <span class="tabBox_tit"
                    >{{ val.cart_info.product.store_name + " | "
                    }}{{ val.cart_info.productAttr.sku }}</span
                  >
                  <span class="tabBox_pice">
                    {{
                      "￥" +
                        val.cart_info.productAttr.price +
                        " x " +
                        val.product_num
                    }}
                    <em
                      v-if="
                        val.refund_num < val.product_num && val.refund_num > 0
                      "
                      style="color: red;font-style: normal;"
                      >(-{{ val.product_num - val.refund_num }})</em
                    >
                  </span>
                  <p style="margin: 4px 0;font-size: 12px;">
                    成本价：￥{{ val.cost }}
                  </p>
                  <p v-if="val.mobile" style="margin: 4px 0;font-size: 12px;">
                    | 选的靓号:{{ val.mobile }}
                  </p>
                </div>
              </div>
            </div>
            <div>
              生产号码：<span>{{ scope.row.phone }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="收货人信息" min-width="250">
          <template slot-scope="scope">
            <div>姓名：{{ scope.row.real_name }}</div>
            <div>身份证号码:{{ scope.row.user_card }}</div>
            <div>联系电话：{{ scope.row.user_phone }}</div>
            <div>收货地址：{{ scope.row.user_address }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="delivery_name" label="订单状态" min-width="210">
          <template slot-scope="scope">
            <div>
              开卡状态：
              <span class="redColor" v-if="scope.row.isSpeed === false"
                >未同步</span
              >
              <span
                v-if="
                  cardStatusList.filter(
                    item => item.type === scope.row.speed_status
                  ).length > 0
                "
                :class="{
                  redColor:
                    cardStatusList.filter(
                      item => item.type === scope.row.speed_status
                    ).length > 0 &&
                    cardStatusList.filter(
                      item => item.type === scope.row.speed_status
                    )[0].name !== '已开卡',
                  greenColor:
                    cardStatusList.filter(
                      item => item.type === scope.row.speed_status
                    ).length > 0 &&
                    cardStatusList.filter(
                      item => item.type === scope.row.speed_status
                    )[0].name == '已开卡'
                }"
              >
                {{
                  cardStatusList.filter(
                    item => item.type === scope.row.speed_status
                  )[0].name
                }}
              </span>
            </div>
            <div>
              激活状态:
              <span class="redColor" v-if="scope.row.open_status === 0"
                >未激活</span
              >
              <span class="greenColor" v-if="scope.row.open_status === 1"
                >已激活</span
              >
            </div>
            <div>
              是否首充：
              <span class="redColor" v-if="scope.row.save_status === 0"
                >未首充</span
              >
              <span class="greenColor" v-if="scope.row.save_status === 1"
                >已首充</span
              >
            </div>
            <div>
              下单时间：<span>{{ scope.row.create_time }}</span>
            </div>
            <div>
              更新时间：<span>{{ scope.row.update_time }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="生产信息" min-width="180">
          <template slot-scope="scope">
            <div>
              物流名称：<span>{{ scope.row.delivery_name }}</span>
            </div>
            <div>物流单号：{{ scope.row.delivery_id }}</div>
            <!-- <div>
              当前佣金：{{
                parseFloat(scope.row.refund_extension_one)
                  ? parseFloat(scope.row.extension_one) +
                    parseFloat(scope.row.refund_extension_one)
                  : parseFloat(scope.row.extension_one)
              }}
              <em
                v-if="scope.row.refund_extension_one > 0"
                style="color: red;font-style: normal;"
                >(-{{ scope.row.refund_extension_one }})</em
              >
            </div> -->
            <!-- <div>当前佣金：{{ scope.row.yj }}</div> -->
            <div>推广人：{{ scope.row.spreadName }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="mark" label="失败原因/备注" min-width="120" />
        <el-table-column
          label="操作"
          min-width="150"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <!-- <span v-for="(val, i) in scope.row.orderProduct" :key="i">
              <el-button
                v-if="orderFilter(scope.row)"
                type="text"
                size="small"
                @click="onRefundDetail(scope.row.order_sn)"
                >查看退款单</el-button
              >
            </span> -->
            <el-button
              type="text"
              size="small"
              @click="onOrderDetails(scope.row.order_id)"
              >详情</el-button
            >
            <!-- <el-button
              v-if="scope.row.status == 0 && scope.row.paid > 0"
              type="text"
              size="small"
              @click="setBackOrder(scope.row)"
              >修改订单</el-button
            > -->
            <!-- <el-button type="text" @click="bingdingSn(scope.row, 'remark')"
              >编辑备注</el-button++++++++++++++++++++++++++++++++++ 560.
                 
            > -->
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <!--导出订单列表-->
    <file-list ref="exportList" />
    <!--详情-->
    <details-from ref="orderDetail" />

    <!-- 实名确认 -->
    <el-dialog
      :title="title"
      :visible.sync="realStatus"
      :close-on-click-modal="false"
    >
      <el-form :model="form">
        <el-form-item label="是否手动录入佣金">
          <el-radio-group v-model="form.resource">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item v-if="form.resource == 1" label="佣金总金额">
          <el-input
            v-model="form.price"
            type="number"
            placeholder="佣金总金额"
            @input="changeNum"
          />
        </el-form-item>
        <el-form-item v-if="form.resource == 1" label="直推佣金">
          <el-input v-model="form.one" type="number" placeholder="直推佣金" />
        </el-form-item>
        <el-form-item v-if="form.resource == 1" label="间推佣金">
          <el-input v-model="form.two" type="number" placeholder="间推佣金" />
        </el-form-item>
        <el-form-item v-if="form.resource == 1" label="团队佣金">
          <el-input v-model="form.team" type="number" placeholder="团队佣金" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="realStatus = false">取 消</el-button>
        <el-button type="primary" @click="saveData">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="dialogTitle"
      :visible.sync="order_three_status"
      width="500px"
      @close="clearBindding"
      :close-on-click-modal="false"
    >
      <el-form :model="threeOrderForm" :rules="rules">
        <el-form-item
          v-if="dialogType === 0"
          label="第三方订单号"
          prop="thrid_order_sn"
        >
          <el-input
            v-model="threeOrderForm.thrid_order_sn"
            placeholder="第三方订单号"
          />
        </el-form-item>
        <el-form-item v-if="dialogType === 1" label="备注" prop="remark">
          <el-input v-model="threeOrderForm.remark" placeholder="备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="clearBindding">取 消</el-button>
        <el-button type="primary" @click="saveThreeOrder">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 重新请求接口提交数据 -->
    <el-dialog
      title="重新请求接口"
      :visible.sync="order_reback_status"
      width="500px"
      @close="clearOrderBack"
      :close-on-click-modal="false"
    >
      <el-form :model="backOrderForm" :rules="backrules" ref="backOrderRef">
        <el-form-item label="姓名" prop="real_name">
          <el-input
            v-model="backOrderForm.real_name"
            placeholder="请输入收货人姓名"
          />
        </el-form-item>
        <el-form-item label="手机号" prop="user_phone">
          <el-input
            v-model="backOrderForm.user_phone"
            placeholder="请输入手机号"
          />
        </el-form-item>
        <el-form-item label="身份证号" prop="user_card">
          <el-input
            v-model="backOrderForm.user_card"
            placeholder="请输入身份证号"
          />
        </el-form-item>
        <el-form-item label="收货城市" prop="user_city">
          <el-cascader
            style="display: block;"
            :class="{ readyCiyt: placeholderText }"
            v-model="backOrderForm.user_city"
            :props="cityProps"
            :options="cityList"
            :placeholder="placeholderText ? placeholderText : '请选择'"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="user_address">
          <el-input
            type="textarea"
            style="display:block;"
            v-model="backOrderForm.user_address"
            placeholder="请输入详细地址"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="clearOrderBack">取 消</el-button>
        <el-button type="primary" @click="resetOrder()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  orderListApi,
  exportOrderApi,
  setRefundoRderListApi,
  adminResetOrder,
  bindDinSnTh,
  adminUpdateOrder,
  orderExportApi
} from "@/api/order";
import { merSelectApi } from "@/api/product";
import detailsFrom from "./orderDetail";
import fileList from "@/components/exportFile/fileList";
import createWorkBook from "@/utils/newToExcel.js";
import cardsData from "@/components/cards/index";
import { fromList } from "@/libs/constants.js";
import { orderRealNameStatus, addBlock } from "@/api/phone";
import { cityDataLst } from "@/api/system.js";
export default {
  components: { detailsFrom, cardsData, fileList },
  data() {
    const validatePhone = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请填写手机号"));
      } else if (!/^1[23456789]\d{9}$/.test(value)) {
        callback(new Error("手机号格式不正确!"));
      } else {
        callback();
      }
    };
    // 检查号码是否符合规范，包括长度，类型
    const isCardNo = (rule, card, callback) => {
      // 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X
      var reg = /(^\d{15}$)|(^\d{17}(\d|X)$)/;
      if (reg.test(card) === false) {
        return callback(new Error("请输入正确的身份证号码"));
      } else {
        callback();
      }
    };
    return {
      orderId: 0,
      tableData: {
        data: [],
        total: 0
      },
      activity: [
        { name: "普通订单", type: 0 },
        { name: "秒杀订单", type: 1 },
        { name: "预售订单", type: 2 },
        { name: "助力订单", type: 3 },
        { name: "拼团订单", type: 4 }
      ],
      payList: [
        { name: "未支付", type: 0 },
        { name: "已支付", type: 1 },
        { name: "退款中", type: 2 },
        { name: "已退款", type: 3 }
      ],
      cardStatusList: [
        { name: "订单取消", type: -1 },
        { name: "待开卡", type: 0 },
        { name: "已开卡", type: 1 },
        { name: "开卡失败", type: 2 }
      ],
      listLoading: true,
      tableFrom: {
        order_sn: this.$route.query.order_sn ? this.$route.query.order_sn : "",
        status: "",
        delivery_id: "",
        order_sn: "",
        store_name: "",
        date: "",
        page: 1,
        limit: 20,
        user_phone: "",
        user_card: "",
        phone: "",
        open_status: "",
        save_status: "",
        speed_status: ""
      },
      pickerMinDate: "",
      pickerOptions: {
        disabledDate: time => {
          if (this.pickerMinDate !== "") {
            const one = 30 * 24 * 3600 * 1000;
            const minTime = this.pickerMinDate - one;
            const maxTime = this.pickerMinDate + one;
            return time.getTime() < minTime || time.getTime() > maxTime;
          }
        },
        onPick: ({ maxDate, minDate }) => {
          this.isRestart = false;
          this.pickerMinDate = minDate.getTime();
          if (maxDate) {
            this.pickerMinDate = "";
          }
        }
      },
      orderChartType: {},
      headeNum: [],
      timeVal: [],
      updateTimeVal: [],
      fromList: fromList,
      selectionList: [],
      ids: "",
      tableFromLog: {
        page: 1,
        limit: 10
      },
      tableDataLog: {
        data: [],
        total: 0
      },
      LogLoading: false,
      dialogVisible: false,
      cardLists: [],
      orderDatalist: null,
      merSelect: [],

      title: "",
      realStatus: false,
      editInfo: {},
      order_three_status: false,
      order_reback_status: false, //重新请求接口窗口控制
      backOrderForm: {
        real_name: "",
        user_phone: "",
        user_card: "",
        user_address: "",
        user_city: ""
      }, //重新请求接口表单
      dialogTitle: "",
      placeholderText: "",
      cityList: [],
      dialogType: "", // 0:编辑订单号，1：编辑备注
      threeOrderForm: {
        order_sn: "",
        thrid_order_sn: "",
        remark: ""
      },
      exportTime: "",
      exportDate: "",

      form: {
        resource: 0,
        price: 0,
        one: 0,
        two: 0,
        team: 0
      },
      rules: {
        thrid_order_sn: [
          { required: true, message: "请输入第三方订单号", trigger: "blur" }
        ],
        remark: [{ required: false, message: "请输入备注", trigger: "blur" }]
      },
      backrules: {
        real_name: [
          { required: true, message: "请输入收货人姓名", trigger: "blur" }
        ],
        user_phone: [
          { required: true, validator: validatePhone, trigger: "blur" }
        ],
        user_card: [{ required: true, validator: isCardNo, trigger: "blur" }],
        user_address: [
          { required: true, message: "请输入详细地址", trigger: "blur" }
        ],
        user_city: [{ required: true, message: "请选择地区", trigger: "blur" }]
      },
      cityProps: {
        lazy: true,
        label: "name",
        value: "id",
        that: this,
        lazyLoad(node, resolve) {
          const { level, value } = node;
          const nodes = null;
          cityDataLst(value)
            .then(res => {
              const nodes = res.data.map(item => ({
                id: item.id,
                name: item.name,
                leaf: level >= 2
              }));
              resolve(nodes);
            })

            .catch(err => {
              this.$message.error(err.message);
            });
        }
      }
    };
  },
  mounted() {
    if (this.$route.query.hasOwnProperty("order_sn")) {
      this.tableFrom.order_sn = this.$route.query.order_sn;
    } else {
      this.tableFrom.order_sn = "";
    }
    this.getList("");
    this.getCity();
  },
  // 被缓存接收参数
  activated() {
    if (this.$route.query.hasOwnProperty("order_sn")) {
      this.tableFrom.order_sn = this.$route.query.order_sn;
    } else {
      this.tableFrom.order_sn = "";
    }
    // this.getMerSelect()
    this.getList("");
  },
  methods: {
    // 退款详情页
    onRefundDetail(sn) {
      console.log(sn, "sn");
      this.$router.push({
        path: "refund",
        query: {
          sn: sn
        }
      });
    },
    searchStore(query) {
      if (query !== "") {
        //
      } else {
      }
    },
    getCity() {
      cityDataLst(0).then(res => {
        this.cityList = res.data;
      });
    },
    chagneTab(e) {
      console.log(e);
    },
    // 订单筛选
    orderFilter(item) {
      let status = false;
      item.orderProduct.forEach(el => {
        if (el.refund_num > 0 && el.refund_num < el.product_num) {
          status = true;
        }
      });
      return status;
    },
    // 表格某一行添加特定的样式
    addTdClass(val) {
      if (val.row.status > 0 && val.row.paid == 1) {
        for (let i = 0; i < val.row.orderProduct.length; i++) {
          if (
            val.row.orderProduct[i].refund_num > 0 &&
            val.row.orderProduct[i].refund_num <
              val.row.orderProduct[i].product_num
          ) {
            return "row-bg";
          }
        }
      } else {
        return " ";
      }
    },
    // 商户列表；
    getMerSelect() {
      merSelectApi()
        .then(res => {
          this.merSelect = res.data;
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    async exports() {
      const excelData = JSON.parse(JSON.stringify(this.tableFrom));
      let data = [];
      excelData.page = 1;
      let pageCount = 1;
      let lebData = {};
      for (let i = 0; i < pageCount; i++) {
        lebData = await this.downData(excelData);
        pageCount = Math.ceil(lebData.count / excelData.limit);
        if (lebData.export.length) {
          data = data.concat(lebData.export);
          excelData.page++;
        }
      }
      createWorkBook(
        lebData.header,
        lebData.title,
        data,
        lebData.foot,
        lebData.filename
      );
      return;
    },

    /**
     * 导出流量卡数据
     * @param {Object} excelData
     */
    // downCardData() {
    //   const excelData = JSON.parse(JSON.stringify(this.tableFrom));
    //   const data = [];
    //   exportCardOrderApi(excelData).then(res => {
    //     const lebData = res.data;
    //     let data = [];
    //     if (lebData.export.length) {
    //       data = data.concat(lebData.export);
    //     }
    //     createWorkBook(
    //       lebData.header,
    //       lebData.title,
    //       data,
    //       lebData.foot,
    //       lebData.filename
    //     );
    //   });
    // },

    /** 订单列表 */
    downData(excelData) {
      return new Promise((resolve, reject) => {
        exportOrderApi(excelData).then(res => {
          return resolve(res.data);
        });
      });
    },
    // 导出
    exportRecord() {
      exportOrderApi(this.tableFrom)
        .then(res => {
          const h = this.$createElement;
          this.$msgbox({
            title: "提示",
            message: h("p", null, [
              h("span", null, '文件正在生成中，请稍后点击"'),
              h("span", { style: "color: teal" }, "导出记录"),
              h("span", null, '"查看~ ')
            ]),
            confirmButtonText: "我知道了"
          }).then(action => {});
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },
    // 导出列表
    getExportFileList() {
      if (this.dateRange) {
        param["date"] = this.dateRange.join("-");
      }
      orderExportApi(this.tableFrom).then(res => {
        const url = `${process.env.VUE_APP_BASE_API}/${res.data.url}`; // 创建 URL 对象
        const link = document.createElement("a"); // 创建 a 标签
        link.href = url; // 设置 href 属性
        document.body.appendChild(link); // 将 a 标签添加到 body 中
        link.click(); // 模拟点击下载
      });
    },
    // // 导出列表
    // getExportFileList() {
    //   this.$refs.exportList.exportFileList();
    // },
    // 详情
    onOrderDetails(id) {
      this.orderId = id;
      this.$refs.orderDetail.dialogVisible = true;
      this.$refs.orderDetail.onOrderDetails(id);
      this.$refs.orderDetail.onOrderLog(id);
    },

    /**
     * 申请退款
     * @param {Object} id
     */
    refundOrder(id) {
      this.$confirm("你确定要进行退款操作吗？")
        .then(res => {
          if (res == "confirm") {
            setRefundoRderListApi(id).then(res => {
              this.$message.success(res.message);
            });
          }
        })
        .catch(res => {});
    },

    setBackOrder(row) {
      this.orderId = row.order_id;
      this.backOrderForm.real_name = row.real_name;
      this.backOrderForm.user_phone = row.user_phone;
      this.backOrderForm.user_card = row.user_card;
      this.backOrderForm.user_address = row.user_address;
      this.backOrderForm.user_city = row.user_city;
      this.order_reback_status = true;
      this.placeholderText = row.user_city.split(",").join("/");
    },
    // 修改订单
    resetOrder() {
      const that = this;
      this.$refs["backOrderRef"].validate(valid => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: "请求中",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)"
          });

          this.$confirm("你确定要重新请求接口吗？")
            .then(res => {
              const params = this.backOrderForm;
              params["user_city"] = this.backOrderForm["user_city"]
                .split(",")
                .join("/");
              params["orderId"] = that.orderId;
              if (res == "confirm") {
                adminUpdateOrder(params).then(res => {
                  loading.close();
                  this.$message.success("成功！");
                });
              }
            })
            .catch(res => {
              loading.close();
              this.$message.error(res.message);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });

      // this.$confirm("你确定要重新请求接口吗？")
      //   .then(res => {
      //     if (res == "confirm") {
      //       adminResetOrder(id).then(res => {
      //         loading.close();
      //         console.log(res);
      //         this.$message.success("成功！");
      //       });
      //     }
      //   })
      //   .catch(res => {
      //     this.$message.error(res.message);
      //   });
    },

    backResetOrder(id) {
      this.$confirm("你确定要重新请求接口吗？")
        .then(res => {
          if (res == "confirm") {
            adminResetOrder(id).then(res => {
              loading.close();
              console.log(res);
              this.$message.success("成功！");
            });
          }
        })
        .catch(res => {
          this.$message.error(res.message);
        });
    },

    // // 绑定第三方订单
    // bingdingSn(row, type) {
    //   if (type === "sn") {
    //     this.dialogTitle = "绑定第三方订单号";
    //     this.dialogType = 0;
    //     this.threeOrderForm.thrid_order_sn = row.thrid_order_sn;
    //   } else if (type === "remark") {
    //     this.dialogTitle = "编辑备注";
    //     this.dialogType = 1;
    //     this.threeOrderForm.remark = row.remark;
    //   }

    //   this.order_three_status = true;
    //   this.threeOrderForm.order_sn = row.order_sn;
    // },

    // 取消第三方订单绑定

    clearBindding() {
      this.order_three_status = false;
      this.$nextTick(() => {
        this.threeOrderForm.order_sn = "";
        this.threeOrderForm.thrid_order_sn = "";
        this.threeOrderForm.remark = "";
      });
    },

    // 取消第三方订单绑定

    clearOrderBack() {
      this.order_reback_status = false;
      this.$nextTick(() => {
        this.$refs["backOrderRef"].resetFields;
      });
    },

    saveThreeOrder() {
      const params = {
        order_sn: this.threeOrderForm.order_sn
      };
      if (this.dialogType === 0) {
        params.thrid_order_sn = this.threeOrderForm.thrid_order_sn;
      } else if (this.dialogType === 1) {
        params.remark = this.threeOrderForm.remark;
      }
      bindDinSnTh(params)
        .then(res => {
          this.getList(1);
          this.order_three_status = false;
        })
        .catch(err => {
          this.$message.error(err.message);
          this.clearBindding();
        });
    },

    pageChangeLog(page) {
      this.tableFromLog.page = page;
      this.getList("");
    },
    handleSizeChangeLog(val) {
      this.tableFromLog.limit = val;
      this.getList("");
    },
    // 导出日期
    changeMonth(e) {
      // 获取当前日期对象
      let currentDate = new Date(e);

      // 获取当月第一天
      let firstDay = new Date(
        currentDate.getFullYear(),
        currentDate.getMonth(),
        1
      );
      // 获取下个月的第一天
      let nextMonth = new Date(
        currentDate.getFullYear(),
        currentDate.getMonth() + 1,
        1
      );
      let lastDay = new Date(nextMonth - 1);
      firstDay = moment(firstDay).format("YYYY/MM/DD");
      lastDay = moment(lastDay).format("YYYY/MM/DD");
      this.exportDate = firstDay + "-" + lastDay;
      // 获取当月最后一天
    },
    // 具体日期
    onchangeTime(e) {
      this.timeVal = e;
      if (e) {
        this.tableFrom.date = e.join("-");
      } else {
        this.tableFrom.date = "";
      }
      this.tableFrom.page = 1;
      this.getList(1);
    },
    // 列表
    getList(num) {
      this.listLoading = true;
      this.tableFrom.page = num || this.tableFrom.page;
      const param = JSON.parse(JSON.stringify(this.tableFrom));
      orderListApi(param)
        .then(res => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.count;
          this.listLoading = false;
        })
        .catch(res => {
          this.$message.error(res.message.response.data.message);
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList("");
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList("");
    },

    /**
     * 设置状态
     * @param {Object} item
     */
    setStatus(item) {
      let tit = "";
      const pro = item.orderProduct[0];
      if (item.activity_type != 6) {
        tit = pro.cart_info.product.store_name;
      } else {
        tit = pro.product_id;
      }

      // item.realNowStatus=1;
      this.editInfo = item;

      // if(status==-1){
      //   this.saveData();
      //   return;
      // }
      this.title = `【${tit}】实名确认`;

      this.realStatus = true;
      return;
    },

    /**
     * 加入黑名单
     * @param {Object} item
     */
    addBlockActive(item) {
      this.$confirm("您确定要把当前身份证加入黑名单并退款吗？")
        .then(res => {
          if (res == "confirm") {
            addBlock(item.order_id)
              .then(res => {
                this.getList(1);
                this.$message.success(res.message);
              })
              .catch(res => {
                this.$message.error(res.message);
              });
          }
        })
        .catch(res => {});
    },

    /**
     * 保存数据
     */
    saveData() {
      const item = this.editInfo;
      const status = this.form.resource;

      const msg = `您确认已经实名了吗？确认后佣金将会解冻！`;

      if (status == 1 && (this.form.price == "" || this.form.price <= 0)) {
        this.$message.error("请输入金额~");
        return;
      }

      this.$confirm(msg)
        .then(res => {
          if (res == "confirm") {
            orderRealNameStatus({
              order_id: item.order_id,
              is_have: this.form.resource,
              price: this.form.price,
              one: this.form.one,
              two: this.form.two,
              team: this.form.team,
              status
            })
              .then(res => {
                this.getList(1);
                this.$message.success(res.message);
              })
              .catch(res => {
                this.$message.error(res.message);
              });
          }
        })
        .catch(res => {});
    },

    changeNum(e) {
      const val = Number(e);
      this.form.one = 0;
      this.form.two = 0;
      if (val != "" && val > 0 && (typeof val === "number" && !isNaN(val))) {
        this.form.one = val * 0.42;
        this.form.two = val * 0.2;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.demo-table-expand {
  /deep/ label {
    width: 83px !important;
  }
}

.selWidth {
  width: 300px;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
  font-size: 12px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.tabBox_tit {
  width: 60%;
  font-size: 12px !important;
  margin: 0 2px 0 10px;
  letter-spacing: 1px;
  padding: 5px 0;
  box-sizing: border-box;
}

/deep/.row-bg {
  .cell {
    color: red !important;
  }
}

/deep/ .readyCiyt {
  .el-input__inner::placeholder {
    color: #606266;
  }

  /* 谷歌 */
  .el-input__inner::-webkit-input-placeholder {
    color: #606266;
  }

  /* 火狐 */
  .el-input__inner:-moz-placeholder {
    color: #606266;
  }

  /*ie*/
  .el-input__inner:-ms-input-placeholder {
    color: #606266;
  }
}

.redColor {
  color: #ed4014;
}

.greenColor {
  color: #67c23a;
}
.link {
  margin-right: 6px;
}
</style>
